package com.first.agent.dao.impl;

import com.first.agent.common.Constants;
import com.first.agent.dao.RoleDao;
import com.first.agent.dbutils.JdbcBuild;
import com.first.agent.pojo.Role;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class RoleDaoImpl extends JdbcBuild implements RoleDao {
    @Override
    public int roleMod(String role_name, Integer status, String role_id) throws SQLException {
        String sql = "update role set role_name=?,status=? where role_id=?";
        Object[] params = {role_name,status,role_id};
        return super.executeUpdate(sql,params);
    }

    @Override
    public int roleAdd(String role_name, Integer status) throws SQLException {
        String sql = "insert into role (role_name,status,role_date) value (?,?,?)";
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String format = simpleDateFormat.format(date);
        Object[] params = {role_name,status,format};
        return super.executeUpdate(sql,params);
    }

    @Override
    public int roleDel(String role_name) throws SQLException {
        String sql = "delete from role where role_name=?";
        Object[] params = {role_name};
        return super.executeUpdate(sql,params);
    }





    @Override
    public List<Role> queryRoleList(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from role where status !=? limit ?,?";
        Object[] params = {Constants.STATUS_DEL,param01,param02};
        return super.queryListEntity(Role.class,sql,params);
    }

    @Override
    public Integer countRole() throws SQLException {
        String sql = "select count(*) from role where status !=?";
        Object[] params = {Constants.STATUS_DEL};
        int result = super.findAllForInt(sql, params);
        return result;
    }


}
